class Solution {
public:
    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {
        vector<int> ret;
        unordered_map<int,int> has;
    
        sort(items.begin(),items.end(),[](const vector<int>& p1,const vector<int>& p2){
            if(p1[0]==p2[0])
                return p1[1]>p2[1];
            return p1[0]<p2[0];
        });

        for(int i=1;i<items.size();i++)
        {
            items[i][1]=max(items[i][1],items[i-1][1]);
        }
        for(int i=0;i<queries.size();i++)
        {
            int t=queries[i];
            int left=0,right=items.size()-1;
            while(left<right)
            {
                int mid=left+(right-left+1)/2;
                if(items[mid][0]>t)
                {
                    right=mid-1;
                }
                else{
                    left=mid;
                }
            }
            if(items[left][0]<=t)
            {
                ret.push_back(items[left][1]);
            }
            else{
                ret.push_back(0);
            }
        }
        return ret;
    }
};
